#include<iostream>
#include<algorithm>

using namespace std;
#define int long long
const int N = 1e5 + 10;
int n;
struct node
{
    int t;
    int d;
}a[N];

bool cmp(node &x , node &y)
{
    return x.t*y.d < y.t*x.d;
}

signed main()
{
    cin >> n;
    for(int i = 1;i <= n;i ++) cin >> a[i].t >> a[i].d;

    sort(a + 1 , a + 1 + n , cmp);

    int ret = 0 , t = 0;
    for(int i = 1;i <= n;i ++)
    {
        ret += a[i].d * t;
        t += 2 * a[i].t;
    }
    cout << ret << endl;
    return 0;
}